package main

import (
	"net/http"
	"gitee.com/winnie_gss/MessageBox/logs"
	"io/ioutil"
	"encoding/json"
	"net/url"
)

type Article struct {
	Id      int    `db:"id"`
	Title   string `db:"title"`
	Content string `db:"content"`
	ViewNum string `db:"viewnum"`
	Time    int64  `db:"time"`
	Time2   string
}

type JsonData1 struct {
	Sort int       `json:"sort"`
	List []Article `json:"list"`
}

type JsonDate2 struct {
	Status bool `json:"status"`
}

type JsonDate3 struct {
	Data Article `json:"data"`
}

func JsonGet(url string, data interface{}) {
	var content []byte
	response, err := http.Get(url)
	logs.ErrorLog(err)

	content, err = ioutil.ReadAll(response.Body)
	logs.ErrorLog(err)

	err = json.Unmarshal(content, data)
	logs.ErrorLog(err)
}

func JsonPost(url string, data interface{}, v url.Values) {
	var content []byte
	response, err := http.PostForm(url, v)
	logs.ErrorLog(err)

	content, err = ioutil.ReadAll(response.Body)
	err = json.Unmarshal(content, data)
	logs.ErrorLog(err)
}
